package com.sangcomz.fishbun.ui.detail.model;

import com.sangcomz.fishbun.adapter.image.ImageAdapter;
import com.sangcomz.fishbun.datasource.FishBunDataSource;
import ohos.utils.net.Uri;

import java.util.List;

public class DetailImageRepositoryImpl implements DetailImageRepository {

    private FishBunDataSource fishBunDataSource;

    public DetailImageRepositoryImpl(FishBunDataSource fishBunDataSource){
        this.fishBunDataSource = fishBunDataSource;
    }

    @Override
    public Uri getPickerImage(int index) {
        List<Uri> pickerImages = fishBunDataSource.getPickerImages();
        if (pickerImages == null || pickerImages.size() <= index){
            return null;
        }else {
            return pickerImages.get(index);
        }
    }

    @Override
    public List<Uri> getPickerImages() {
        return fishBunDataSource.getPickerImages();
    }

    @Override
    public boolean isSelected(Uri imageUri) {
        return fishBunDataSource.getSelectedImageList().contains(imageUri);
    }

    @Override
    public int getImageIndex(Uri imageUri) {
        return fishBunDataSource.getSelectedImageList().indexOf(imageUri);
    }

    @Override
    public void selectImage(Uri imageUri) {
        fishBunDataSource.selectImage(imageUri);
    }

    @Override
    public void unselectImage(Uri imageUri) {
        fishBunDataSource.unselectImage(imageUri);
    }

    @Override
    public ImageAdapter getImageAdapter() {
        return fishBunDataSource.getImageAdapter();
    }

    @Override
    public boolean isFullSelected() {
        return fishBunDataSource.getSelectedImageList().size() == fishBunDataSource.getMaxCount();
    }


    @Override
    public boolean checkForFinish() {
        return fishBunDataSource.getIsAutomaticClose() && isFullSelected();
    }

    @Override
    public String getMessageLimitReached() {
        return fishBunDataSource.getMessageLimitReached();
    }

    @Override
    public int getMaxCount() {
        return fishBunDataSource.getMaxCount();
    }

    @Override
    public DetailImageViewData getDetailPickerViewData() {
        return fishBunDataSource.getDetailViewData();
    }
}